package com.yixun.qfbao.hander;

import com.yixun.qfbao.api.service.OrganizationService;
import com.yixun.qfbao.apidto.ChangeDeptReqDto;
import com.yixun.qfbao.apidto.ChangeDeptResDto;
import com.yixun.qfbao.apidto.MergeDeptResDto;
import com.yixun.qfbao.dto.base.BaseRequestDTO;
import com.yixun.qfbao.dto.base.BaseResponseDTO;
import com.yixun.qfbao.hander.base.CommonAbstractHander;
import com.yixun.qfbao.util.exception.TServerException;
import com.yixun.qfbao.vo.ChangeDeptReqVo;
import com.yixun.qfbao.xf.model.enums.ResultEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Description
 * @Date 2017/12/20
 * @Author sangtao
 * @Computer Administrator
 */
@Service("changeDeptHander")
public class ChangeDeptHander extends CommonAbstractHander {
    private static Logger logger= LoggerFactory.getLogger(ChangeDeptHander.class);
    @Autowired
    private OrganizationService organizationService;

    @Override
    public BaseResponseDTO doBusiness(BaseRequestDTO reqDto) {
        ChangeDeptReqVo req = (ChangeDeptReqVo)reqDto;
        ChangeDeptReqDto reqDto1 = req.getParams();
        BaseResponseDTO<ChangeDeptResDto> res = new BaseResponseDTO<ChangeDeptResDto>();
        ChangeDeptResDto resDto = new ChangeDeptResDto();
        try {
            resDto = organizationService.changeDept(reqDto1);
        }catch(TServerException e){
            resDto.setResult(ResultEnum.FAIL.getNo());
            resDto.setResultMsg(e.getErrorMsg());
        } catch (Exception e) {
            logger.error("ChangeDeptHander error: {}", e);
            resDto.setResult(ResultEnum.FAIL.getNo());
            resDto.setResultMsg("系统异常");
        }
        res.setResData(resDto);
        res.setResult(resDto.getResult());
        return res;
    }
}
